@8btc/mditor 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +8 -14
- package/dist/index.js +297 -35
- package/dist/index.min.js +1 -1
- package/dist/method.js +3 -3
- package/dist/method.min.js +1 -1
- package/dist/ts/util/attachLineNumbers.d.ts +6 -0
- package/package.json +1 -1
- package/src/assets/less/_line-number.less +17 -10
- package/src/ts/ir/process.ts +127 -40
- package/src/ts/sv/process.ts +107 -41
- package/src/ts/util/attachLineNumbers.ts +437 -0
- package/src/ts/wysiwyg/afterRenderEvent.ts +17 -7
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.1 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
27
|
/*!
|
|
28
|
-
* Vditor v0.0.
|
|
28
|
+
* Vditor v0.0.1 - A markdown editor written in TypeScript.
|
|
29
29
|
*
|
|
30
30
|
* MIT License
|
|
31
31
|
*
|
|
@@ -1084,7 +1084,7 @@
|
|
|
1084
1084
|
fill: currentColor;
|
|
1085
1085
|
}
|
|
1086
1086
|
.vditor-linenumber {
|
|
1087
|
-
padding-left:
|
|
1087
|
+
padding-left: 4em !important;
|
|
1088
1088
|
position: relative;
|
|
1089
1089
|
}
|
|
1090
1090
|
.vditor-linenumber__rows {
|
|
@@ -1809,21 +1809,15 @@
|
|
|
1809
1809
|
.vditor-sv__marker--strong {
|
|
1810
1810
|
font-weight: bold;
|
|
1811
1811
|
}
|
|
1812
|
-
.vditor--linenumber .vditor-reset
|
|
1813
|
-
|
|
1814
|
-
padding-left: calc(4em + 20px);
|
|
1815
|
-
/* 行号栏位 + 额外 20px 左间距 */
|
|
1816
|
-
}
|
|
1817
|
-
.vditor--linenumber .vditor-reset > ul::before,
|
|
1818
|
-
.vditor--linenumber .vditor-reset ol::before {
|
|
1812
|
+
.vditor--linenumber .vditor-reset > ul [data-linenumber]:before,
|
|
1813
|
+
.vditor--linenumber .vditor-reset ol [data-linenumber]:before {
|
|
1819
1814
|
margin-left: -4.5rem !important;
|
|
1820
1815
|
}
|
|
1821
|
-
.vditor--linenumber .vditor-reset
|
|
1816
|
+
.vditor--linenumber .vditor-reset [data-linenumber] {
|
|
1822
1817
|
position: relative;
|
|
1823
|
-
counter-increment: linenumber;
|
|
1824
1818
|
}
|
|
1825
|
-
.vditor--linenumber .vditor-reset
|
|
1826
|
-
content:
|
|
1819
|
+
.vditor--linenumber .vditor-reset [data-linenumber]:before {
|
|
1820
|
+
content: attr(data-linenumber);
|
|
1827
1821
|
float: left;
|
|
1828
1822
|
padding-right: 0.25rem;
|
|
1829
1823
|
margin-left: -2.5rem;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.1 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -2791,7 +2791,7 @@ var Vditor = /** @class */ (function () {
|
|
|
2791
2791
|
/* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
|
|
2792
2792
|
/* harmony export */ "g": () => (/* binding */ Constants)
|
|
2793
2793
|
/* harmony export */ });
|
|
2794
|
-
var _VDITOR_VERSION = "0.0.
|
|
2794
|
+
var _VDITOR_VERSION = "0.0.1";
|
|
2795
2795
|
|
|
2796
2796
|
var Constants = /** @class */ (function () {
|
|
2797
2797
|
function Constants() {
|
|
@@ -3093,7 +3093,7 @@ var Constants = /** @class */ (function () {
|
|
|
3093
3093
|
"c#",
|
|
3094
3094
|
"bat",
|
|
3095
3095
|
];
|
|
3096
|
-
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.
|
|
3096
|
+
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.1");
|
|
3097
3097
|
Constants.MARKDOWN_OPTIONS = {
|
|
3098
3098
|
autoSpace: false,
|
|
3099
3099
|
gfmAutoLink: true,
|
|
@@ -8510,13 +8510,17 @@ var setPadding = function (vditor) {
|
|
|
8510
8510
|
var padding = (vditor.wysiwyg.element.parentElement.clientWidth -
|
|
8511
8511
|
vditor.options.preview.maxWidth) /
|
|
8512
8512
|
2;
|
|
8513
|
-
|
|
8513
|
+
var basePad = Math.max(minPadding, padding);
|
|
8514
|
+
var leftExtra = vditor.options.lineNumber && basePad < 40 ? 20 : 0;
|
|
8515
|
+
vditor.wysiwyg.element.style.padding = "10px ".concat(basePad, "px 10px ").concat(basePad + leftExtra, "px");
|
|
8514
8516
|
}
|
|
8515
8517
|
if (vditor.ir.element.parentElement.style.display !== "none") {
|
|
8516
8518
|
var padding = (vditor.ir.element.parentElement.clientWidth -
|
|
8517
8519
|
vditor.options.preview.maxWidth) /
|
|
8518
8520
|
2;
|
|
8519
|
-
|
|
8521
|
+
var basePad = Math.max(minPadding, padding);
|
|
8522
|
+
var leftExtra = vditor.options.lineNumber && basePad < 40 ? 20 : 0;
|
|
8523
|
+
vditor.ir.element.style.padding = "10px ".concat(basePad, "px 10px ").concat(basePad + leftExtra, "px");
|
|
8520
8524
|
}
|
|
8521
8525
|
if (vditor.preview.element.style.display !== "block") {
|
|
8522
8526
|
vditor.toolbar.element.style.paddingLeft =
|
|
@@ -8672,9 +8676,202 @@ var highlightToolbarIR = function (vditor) {
|
|
|
8672
8676
|
}, 200);
|
|
8673
8677
|
};
|
|
8674
8678
|
|
|
8679
|
+
;// CONCATENATED MODULE: ./src/ts/util/attachLineNumbers.ts
|
|
8680
|
+
/**
|
|
8681
|
+
* 为编辑区域中所有包含 `data-block` 的块级节点添加 `data-linenumber` 属性。
|
|
8682
|
+
* 通过解析传入的 Markdown 源文本,建立块内容到源文件行号的映射,
|
|
8683
|
+
* 并在 DOM 上写入对应的行号,兼顾多行文本、重复内容以及空白/特殊字符。
|
|
8684
|
+
*/
|
|
8685
|
+
var attachLineNumbersToBlocks = function (root, sourceMarkdown) {
|
|
8686
|
+
if (!root || !sourceMarkdown) {
|
|
8687
|
+
return;
|
|
8688
|
+
}
|
|
8689
|
+
var ZWSP = "\u200b";
|
|
8690
|
+
var normalize = function (text) {
|
|
8691
|
+
return text
|
|
8692
|
+
.replace(/\r\n|\r/g, "\n")
|
|
8693
|
+
.replace(new RegExp(ZWSP, "g"), "")
|
|
8694
|
+
.replace(/\u00a0/g, " ")
|
|
8695
|
+
.replace(/\u2006/g, "")
|
|
8696
|
+
.replace(/[\t\f\v ]+/g, " ");
|
|
8697
|
+
};
|
|
8698
|
+
var srcNorm = normalize(sourceMarkdown);
|
|
8699
|
+
var srcLines = srcNorm.split("\n");
|
|
8700
|
+
var stripInlineMD = function (text) {
|
|
8701
|
+
return (text
|
|
8702
|
+
.replace(/\\([*_`~])/g, "$1")
|
|
8703
|
+
.replace(/\*\*|__/g, "")
|
|
8704
|
+
.replace(/\*|_/g, "")
|
|
8705
|
+
.replace(/~~/g, "")
|
|
8706
|
+
.replace(/`+/g, "")
|
|
8707
|
+
// 数学行内分隔符:保留内容,仅移除分隔符
|
|
8708
|
+
.replace(/\\\(/g, "(")
|
|
8709
|
+
.replace(/\\\)/g, ")")
|
|
8710
|
+
.replace(/\\\[/g, "[")
|
|
8711
|
+
.replace(/\\\]/g, "]")
|
|
8712
|
+
.replace(/\$/g, "")
|
|
8713
|
+
.trim());
|
|
8714
|
+
};
|
|
8715
|
+
var strippedLines = srcLines.map(function (l) { return stripInlineMD(l); });
|
|
8716
|
+
var lineLookup = new Map();
|
|
8717
|
+
for (var i = 0; i < strippedLines.length; i++) {
|
|
8718
|
+
var key = strippedLines[i];
|
|
8719
|
+
if (!lineLookup.has(key)) {
|
|
8720
|
+
lineLookup.set(key, [i + 1]);
|
|
8721
|
+
}
|
|
8722
|
+
else {
|
|
8723
|
+
lineLookup.get(key).push(i + 1);
|
|
8724
|
+
}
|
|
8725
|
+
}
|
|
8726
|
+
var usedLines = new Set();
|
|
8727
|
+
var pickFirstUnused = function (candidates) {
|
|
8728
|
+
if (!candidates || candidates.length === 0)
|
|
8729
|
+
return -1;
|
|
8730
|
+
for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
|
|
8731
|
+
var ln = candidates_1[_i];
|
|
8732
|
+
if (!usedLines.has(ln))
|
|
8733
|
+
return ln;
|
|
8734
|
+
}
|
|
8735
|
+
return -1;
|
|
8736
|
+
};
|
|
8737
|
+
var findLineNumberByText = function (text) {
|
|
8738
|
+
var stripped = stripInlineMD(text);
|
|
8739
|
+
var ln = pickFirstUnused(lineLookup.get(stripped));
|
|
8740
|
+
if (ln !== -1)
|
|
8741
|
+
return ln;
|
|
8742
|
+
for (var i = 0; i < strippedLines.length; i++) {
|
|
8743
|
+
if (!usedLines.has(i + 1) &&
|
|
8744
|
+
stripped &&
|
|
8745
|
+
strippedLines[i].indexOf(stripped) !== -1) {
|
|
8746
|
+
return i + 1;
|
|
8747
|
+
}
|
|
8748
|
+
}
|
|
8749
|
+
return -1;
|
|
8750
|
+
};
|
|
8751
|
+
var blocks = root.querySelectorAll("[data-block]");
|
|
8752
|
+
blocks.forEach(function (el) {
|
|
8753
|
+
try {
|
|
8754
|
+
var text = el.textContent || "";
|
|
8755
|
+
var normText = normalize(text);
|
|
8756
|
+
// 跳过纯空白块
|
|
8757
|
+
if (!normText.trim()) {
|
|
8758
|
+
el.setAttribute("data-linenumber", "");
|
|
8759
|
+
return;
|
|
8760
|
+
}
|
|
8761
|
+
var lineNumber = -1;
|
|
8762
|
+
var tag_1 = el.tagName;
|
|
8763
|
+
if (tag_1 === "UL" || tag_1 === "OL") {
|
|
8764
|
+
var listEl = el;
|
|
8765
|
+
var items = Array.from(listEl.querySelectorAll(":scope > li"));
|
|
8766
|
+
var cursor_1 = 0;
|
|
8767
|
+
items.forEach(function (liEl) {
|
|
8768
|
+
var raw = normalize(liEl.textContent || "");
|
|
8769
|
+
if (!raw.trim()) {
|
|
8770
|
+
liEl.setAttribute("data-linenumber", "");
|
|
8771
|
+
return;
|
|
8772
|
+
}
|
|
8773
|
+
var firstLine = raw.split("\n").find(function (l) { return l.trim().length > 0; }) || raw;
|
|
8774
|
+
var strippedLi = stripInlineMD(firstLine);
|
|
8775
|
+
var ln = -1;
|
|
8776
|
+
if (tag_1 === "UL") {
|
|
8777
|
+
for (var i = Math.max(0, cursor_1); i < srcLines.length; i++) {
|
|
8778
|
+
if (usedLines.has(i + 1))
|
|
8779
|
+
continue;
|
|
8780
|
+
var s = srcLines[i];
|
|
8781
|
+
if (/^\s*[-*+]\s+/.test(s)) {
|
|
8782
|
+
var content = stripInlineMD(s.replace(/^\s*[-*+]\s+(\[[ xX]\]\s+)?/, ""));
|
|
8783
|
+
if (content.indexOf(strippedLi) !== -1) {
|
|
8784
|
+
ln = i + 1;
|
|
8785
|
+
cursor_1 = i + 1;
|
|
8786
|
+
break;
|
|
8787
|
+
}
|
|
8788
|
+
}
|
|
8789
|
+
}
|
|
8790
|
+
}
|
|
8791
|
+
else {
|
|
8792
|
+
for (var i = Math.max(0, cursor_1); i < srcLines.length; i++) {
|
|
8793
|
+
if (usedLines.has(i + 1))
|
|
8794
|
+
continue;
|
|
8795
|
+
var s = srcLines[i];
|
|
8796
|
+
if (/^\s*\d+\.\s+/.test(s)) {
|
|
8797
|
+
var content = stripInlineMD(s.replace(/^\s*\d+\.\s+/, ""));
|
|
8798
|
+
if (content.indexOf(strippedLi) !== -1) {
|
|
8799
|
+
ln = i + 1;
|
|
8800
|
+
cursor_1 = i + 1;
|
|
8801
|
+
break;
|
|
8802
|
+
}
|
|
8803
|
+
}
|
|
8804
|
+
}
|
|
8805
|
+
}
|
|
8806
|
+
if (ln === -1) {
|
|
8807
|
+
for (var i = 0; i < srcLines.length; i++) {
|
|
8808
|
+
if (usedLines.has(i + 1))
|
|
8809
|
+
continue;
|
|
8810
|
+
var s = srcLines[i];
|
|
8811
|
+
var isListLine = tag_1 === "UL"
|
|
8812
|
+
? /^\s*[-*+]\s+/.test(s)
|
|
8813
|
+
: /^\s*\d+\.\s+/.test(s);
|
|
8814
|
+
if (!isListLine)
|
|
8815
|
+
continue;
|
|
8816
|
+
var content = stripInlineMD(tag_1 === "UL"
|
|
8817
|
+
? s.replace(/^\s*[-*+]\s+(\[[ xX]\]\s+)?/, "")
|
|
8818
|
+
: s.replace(/^\s*\d+\.\s+/, ""));
|
|
8819
|
+
if (content.indexOf(strippedLi) !== -1) {
|
|
8820
|
+
ln = i + 1;
|
|
8821
|
+
cursor_1 = i + 1;
|
|
8822
|
+
break;
|
|
8823
|
+
}
|
|
8824
|
+
}
|
|
8825
|
+
}
|
|
8826
|
+
if (ln !== -1) {
|
|
8827
|
+
usedLines.add(ln);
|
|
8828
|
+
liEl.setAttribute("data-linenumber", String(ln));
|
|
8829
|
+
}
|
|
8830
|
+
else {
|
|
8831
|
+
liEl.setAttribute("data-linenumber", "");
|
|
8832
|
+
}
|
|
8833
|
+
});
|
|
8834
|
+
return;
|
|
8835
|
+
}
|
|
8836
|
+
else if (tag_1 === "BLOCKQUOTE") {
|
|
8837
|
+
var firstLine = normText.split("\n").find(function (l) { return l.trim().length > 0; }) ||
|
|
8838
|
+
normText;
|
|
8839
|
+
var stripped = stripInlineMD(firstLine);
|
|
8840
|
+
for (var i = 0; i < srcLines.length; i++) {
|
|
8841
|
+
if (usedLines.has(i + 1))
|
|
8842
|
+
continue;
|
|
8843
|
+
if (/^\s*>+\s/.test(srcLines[i])) {
|
|
8844
|
+
var content = stripInlineMD(srcLines[i].replace(/^\s*>+\s+/, ""));
|
|
8845
|
+
if (content.indexOf(stripped) !== -1) {
|
|
8846
|
+
lineNumber = i + 1;
|
|
8847
|
+
break;
|
|
8848
|
+
}
|
|
8849
|
+
}
|
|
8850
|
+
}
|
|
8851
|
+
}
|
|
8852
|
+
else {
|
|
8853
|
+
var firstLine = normText.split("\n").find(function (l) { return l.trim().length > 0; }) ||
|
|
8854
|
+
normText;
|
|
8855
|
+
lineNumber = findLineNumberByText(firstLine);
|
|
8856
|
+
}
|
|
8857
|
+
if (lineNumber !== -1) {
|
|
8858
|
+
usedLines.add(lineNumber);
|
|
8859
|
+
el.setAttribute("data-linenumber", String(lineNumber));
|
|
8860
|
+
}
|
|
8861
|
+
else {
|
|
8862
|
+
el.setAttribute("data-linenumber", "");
|
|
8863
|
+
}
|
|
8864
|
+
}
|
|
8865
|
+
catch (_a) {
|
|
8866
|
+
void 0;
|
|
8867
|
+
}
|
|
8868
|
+
});
|
|
8869
|
+
};
|
|
8870
|
+
|
|
8675
8871
|
;// CONCATENATED MODULE: ./src/ts/wysiwyg/afterRenderEvent.ts
|
|
8676
8872
|
|
|
8677
8873
|
|
|
8874
|
+
|
|
8678
8875
|
var afterRenderEvent = function (vditor, options) {
|
|
8679
8876
|
if (options === void 0) { options = {
|
|
8680
8877
|
enableAddUndoStack: true,
|
|
@@ -8708,6 +8905,12 @@ var afterRenderEvent = function (vditor, options) {
|
|
|
8708
8905
|
if (options.enableAddUndoStack) {
|
|
8709
8906
|
vditor.undo.addToUndoStack(vditor);
|
|
8710
8907
|
}
|
|
8908
|
+
try {
|
|
8909
|
+
attachLineNumbersToBlocks(vditor.wysiwyg.element, text);
|
|
8910
|
+
}
|
|
8911
|
+
catch (_a) {
|
|
8912
|
+
void 0;
|
|
8913
|
+
}
|
|
8711
8914
|
}, vditor.options.undoDelay);
|
|
8712
8915
|
};
|
|
8713
8916
|
|
|
@@ -11193,6 +11396,7 @@ var selectEvent = function (vditor, editorElement) {
|
|
|
11193
11396
|
|
|
11194
11397
|
|
|
11195
11398
|
|
|
11399
|
+
|
|
11196
11400
|
var processPaste = function (vditor, text) {
|
|
11197
11401
|
var range = (0,selection/* getEditorRange */.zh)(vditor);
|
|
11198
11402
|
range.extractContents();
|
|
@@ -11203,9 +11407,10 @@ var processPaste = function (vditor, text) {
|
|
|
11203
11407
|
blockElement = vditor.sv.element;
|
|
11204
11408
|
}
|
|
11205
11409
|
var spinHTML = vditor.lute.SpinVditorSVDOM(blockElement.textContent);
|
|
11206
|
-
spinHTML =
|
|
11207
|
-
|
|
11208
|
-
|
|
11410
|
+
spinHTML =
|
|
11411
|
+
"<div data-block='0'>" +
|
|
11412
|
+
spinHTML.replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
|
|
11413
|
+
"</div>";
|
|
11209
11414
|
if (blockElement.isEqualNode(vditor.sv.element)) {
|
|
11210
11415
|
blockElement.innerHTML = spinHTML;
|
|
11211
11416
|
}
|
|
@@ -11238,9 +11443,10 @@ var getSideByType = function (spanNode, type, isPrevious) {
|
|
|
11238
11443
|
var processSpinVditorSVDOM = function (html, vditor) {
|
|
11239
11444
|
log("SpinVditorSVDOM", html, "argument", vditor.options.debugger);
|
|
11240
11445
|
var spinHTML = vditor.lute.SpinVditorSVDOM(html);
|
|
11241
|
-
html =
|
|
11242
|
-
|
|
11243
|
-
|
|
11446
|
+
html =
|
|
11447
|
+
"<div data-block='0'>" +
|
|
11448
|
+
spinHTML.replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
|
|
11449
|
+
"</div>";
|
|
11244
11450
|
log("SpinVditorSVDOM", html, "result", vditor.options.debugger);
|
|
11245
11451
|
return html;
|
|
11246
11452
|
};
|
|
@@ -11248,21 +11454,32 @@ var processPreviousMarkers = function (spanElement) {
|
|
|
11248
11454
|
var spanType = spanElement.getAttribute("data-type");
|
|
11249
11455
|
var previousElement = spanElement.previousElementSibling;
|
|
11250
11456
|
// 有内容的子列表/标题,在其 marker 后换行
|
|
11251
|
-
var markerText =
|
|
11252
|
-
spanType !== "
|
|
11253
|
-
|
|
11254
|
-
|
|
11457
|
+
var markerText = spanType &&
|
|
11458
|
+
spanType !== "text" &&
|
|
11459
|
+
spanType !== "table" &&
|
|
11460
|
+
spanType !== "heading-marker" &&
|
|
11461
|
+
spanType !== "newline" &&
|
|
11462
|
+
spanType !== "yaml-front-matter-open-marker" &&
|
|
11463
|
+
spanType !== "yaml-front-matter-close-marker" &&
|
|
11464
|
+
spanType !== "code-block-info" &&
|
|
11465
|
+
spanType !== "code-block-close-marker" &&
|
|
11466
|
+
spanType !== "code-block-open-marker"
|
|
11467
|
+
? spanElement.textContent
|
|
11468
|
+
: "";
|
|
11255
11469
|
var hasNL = false;
|
|
11256
11470
|
if (spanType === "newline") {
|
|
11257
11471
|
hasNL = true;
|
|
11258
11472
|
}
|
|
11259
11473
|
while (previousElement && !hasNL) {
|
|
11260
11474
|
var previousType = previousElement.getAttribute("data-type");
|
|
11261
|
-
if (previousType === "li-marker" ||
|
|
11475
|
+
if (previousType === "li-marker" ||
|
|
11476
|
+
previousType === "blockquote-marker" ||
|
|
11477
|
+
previousType === "task-marker" ||
|
|
11262
11478
|
previousType === "padding") {
|
|
11263
11479
|
var previousText = previousElement.textContent;
|
|
11264
11480
|
if (previousType === "li-marker" &&
|
|
11265
|
-
(spanType === "code-block-open-marker" ||
|
|
11481
|
+
(spanType === "code-block-open-marker" ||
|
|
11482
|
+
spanType === "code-block-info")) {
|
|
11266
11483
|
// https://github.com/Vanessa219/vditor/issues/586
|
|
11267
11484
|
markerText = previousText.replace(/\S/g, " ") + markerText;
|
|
11268
11485
|
}
|
|
@@ -11317,6 +11534,12 @@ var processAfterRender = function (vditor, options) {
|
|
|
11317
11534
|
if (options.enableAddUndoStack && !vditor.sv.composingLock) {
|
|
11318
11535
|
vditor.undo.addToUndoStack(vditor);
|
|
11319
11536
|
}
|
|
11537
|
+
try {
|
|
11538
|
+
attachLineNumbersToBlocks(vditor.sv.element, text);
|
|
11539
|
+
}
|
|
11540
|
+
catch (_a) {
|
|
11541
|
+
void 0;
|
|
11542
|
+
}
|
|
11320
11543
|
}, vditor.options.undoDelay);
|
|
11321
11544
|
};
|
|
11322
11545
|
var processHeading = function (vditor, value) {
|
|
@@ -11352,8 +11575,13 @@ var processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
|
11352
11575
|
document.execCommand("insertHTML", false, html);
|
|
11353
11576
|
return;
|
|
11354
11577
|
}
|
|
11355
|
-
else if (commandName === "italic" ||
|
|
11356
|
-
commandName === "
|
|
11578
|
+
else if (commandName === "italic" ||
|
|
11579
|
+
commandName === "bold" ||
|
|
11580
|
+
commandName === "strike" ||
|
|
11581
|
+
commandName === "inline-code" ||
|
|
11582
|
+
commandName === "code" ||
|
|
11583
|
+
commandName === "table" ||
|
|
11584
|
+
commandName === "line") {
|
|
11357
11585
|
var html = void 0;
|
|
11358
11586
|
// https://github.com/Vanessa219/vditor/issues/563 代码块不需要后面的 ```
|
|
11359
11587
|
if (range.toString() === "") {
|
|
@@ -11362,7 +11590,10 @@ var processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
|
11362
11590
|
else {
|
|
11363
11591
|
html = "".concat(prefix).concat(range.toString()).concat(Lute.Caret).concat(commandName === "code" ? "" : suffix);
|
|
11364
11592
|
}
|
|
11365
|
-
if (commandName === "table" ||
|
|
11593
|
+
if (commandName === "table" ||
|
|
11594
|
+
(commandName === "code" &&
|
|
11595
|
+
spanElement &&
|
|
11596
|
+
spanElement.textContent !== "")) {
|
|
11366
11597
|
html = "\n\n" + html;
|
|
11367
11598
|
}
|
|
11368
11599
|
else if (commandName === "line") {
|
|
@@ -11371,7 +11602,9 @@ var processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
|
11371
11602
|
document.execCommand("insertHTML", false, html);
|
|
11372
11603
|
return;
|
|
11373
11604
|
}
|
|
11374
|
-
else if (commandName === "check" ||
|
|
11605
|
+
else if (commandName === "check" ||
|
|
11606
|
+
commandName === "list" ||
|
|
11607
|
+
commandName === "ordered-list" ||
|
|
11375
11608
|
commandName === "quote") {
|
|
11376
11609
|
if (spanElement) {
|
|
11377
11610
|
var marker = "* ";
|
|
@@ -13678,6 +13911,7 @@ var templateObject_1;
|
|
|
13678
13911
|
|
|
13679
13912
|
|
|
13680
13913
|
|
|
13914
|
+
|
|
13681
13915
|
var processHint = function (vditor) {
|
|
13682
13916
|
var _a, _b;
|
|
13683
13917
|
vditor.hint.render(vditor);
|
|
@@ -13685,16 +13919,20 @@ var processHint = function (vditor) {
|
|
|
13685
13919
|
// 代码块语言提示
|
|
13686
13920
|
var preBeforeElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "code-block-info");
|
|
13687
13921
|
if (preBeforeElement) {
|
|
13688
|
-
if (preBeforeElement.textContent.replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
|
|
13689
|
-
|
|
13922
|
+
if (preBeforeElement.textContent.replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
|
|
13923
|
+
vditor.hint.recentLanguage) {
|
|
13924
|
+
preBeforeElement.textContent =
|
|
13925
|
+
constants/* Constants.ZWSP */.g.ZWSP + vditor.hint.recentLanguage;
|
|
13690
13926
|
var range = (0,selection/* getEditorRange */.zh)(vditor);
|
|
13691
13927
|
range.selectNodeContents(preBeforeElement);
|
|
13692
13928
|
}
|
|
13693
13929
|
else {
|
|
13694
13930
|
var matchLangData_1 = [];
|
|
13695
|
-
var key_1 = preBeforeElement.textContent
|
|
13931
|
+
var key_1 = preBeforeElement.textContent
|
|
13932
|
+
.substring(0, (0,selection/* getSelectPosition */.im)(preBeforeElement, vditor.ir.element).start)
|
|
13696
13933
|
.replace(constants/* Constants.ZWSP */.g.ZWSP, "");
|
|
13697
|
-
(vditor.options.preview.hljs.langs ||
|
|
13934
|
+
(vditor.options.preview.hljs.langs ||
|
|
13935
|
+
constants/* Constants.ALIAS_CODE_LANGUAGES.concat */.g.ALIAS_CODE_LANGUAGES.concat(((_b = (_a = window.hljs) === null || _a === void 0 ? void 0 : _a.listLanguages()) !== null && _b !== void 0 ? _b : []).sort())).forEach(function (keyName) {
|
|
13698
13936
|
if (keyName.indexOf(key_1.toLowerCase()) > -1) {
|
|
13699
13937
|
matchLangData_1.push({
|
|
13700
13938
|
html: keyName,
|
|
@@ -13739,11 +13977,18 @@ var process_processAfterRender = function (vditor, options) {
|
|
|
13739
13977
|
if (options.enableAddUndoStack) {
|
|
13740
13978
|
vditor.undo.addToUndoStack(vditor);
|
|
13741
13979
|
}
|
|
13980
|
+
try {
|
|
13981
|
+
attachLineNumbersToBlocks(vditor.ir.element, text);
|
|
13982
|
+
}
|
|
13983
|
+
catch (_a) {
|
|
13984
|
+
void 0;
|
|
13985
|
+
}
|
|
13742
13986
|
}, vditor.options.undoDelay);
|
|
13743
13987
|
};
|
|
13744
13988
|
var process_processHeading = function (vditor, value) {
|
|
13745
13989
|
var range = (0,selection/* getEditorRange */.zh)(vditor);
|
|
13746
|
-
var headingElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer) ||
|
|
13990
|
+
var headingElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer) ||
|
|
13991
|
+
range.startContainer;
|
|
13747
13992
|
if (headingElement) {
|
|
13748
13993
|
var headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading");
|
|
13749
13994
|
if (headingMarkerElement) {
|
|
@@ -13766,7 +14011,8 @@ var removeInline = function (range, vditor, type) {
|
|
|
13766
14011
|
range.insertNode(document.createElement("wbr"));
|
|
13767
14012
|
var tempElement = document.createElement("div");
|
|
13768
14013
|
tempElement.innerHTML = vditor.lute.SpinVditorIRDOM(inlineElement.outerHTML);
|
|
13769
|
-
inlineElement.outerHTML =
|
|
14014
|
+
inlineElement.outerHTML =
|
|
14015
|
+
tempElement.firstElementChild.innerHTML.trim();
|
|
13770
14016
|
}
|
|
13771
14017
|
};
|
|
13772
14018
|
var process_processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
@@ -13783,8 +14029,10 @@ var process_processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
|
13783
14029
|
var quoteElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "BLOCKQUOTE");
|
|
13784
14030
|
if (quoteElement) {
|
|
13785
14031
|
range.insertNode(document.createElement("wbr"));
|
|
13786
|
-
quoteElement.outerHTML =
|
|
13787
|
-
|
|
14032
|
+
quoteElement.outerHTML =
|
|
14033
|
+
quoteElement.innerHTML.trim() === ""
|
|
14034
|
+
? "<p data-block=\"0\">".concat(quoteElement.innerHTML, "</p>")
|
|
14035
|
+
: quoteElement.innerHTML;
|
|
13788
14036
|
}
|
|
13789
14037
|
}
|
|
13790
14038
|
else if (commandName === "link") {
|
|
@@ -13796,7 +14044,9 @@ var process_processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
|
13796
14044
|
aElement.outerHTML = aTextElement.innerHTML;
|
|
13797
14045
|
}
|
|
13798
14046
|
else {
|
|
13799
|
-
aElement.outerHTML =
|
|
14047
|
+
aElement.outerHTML =
|
|
14048
|
+
aElement.querySelector(".vditor-ir__link").innerHTML +
|
|
14049
|
+
"<wbr>";
|
|
13800
14050
|
}
|
|
13801
14051
|
}
|
|
13802
14052
|
}
|
|
@@ -13812,7 +14062,9 @@ var process_processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
|
13812
14062
|
else if (commandName === "inline-code") {
|
|
13813
14063
|
removeInline(range, vditor, "code");
|
|
13814
14064
|
}
|
|
13815
|
-
else if (commandName === "check" ||
|
|
14065
|
+
else if (commandName === "check" ||
|
|
14066
|
+
commandName === "list" ||
|
|
14067
|
+
commandName === "ordered-list") {
|
|
13816
14068
|
listToggle(vditor, range, commandName);
|
|
13817
14069
|
useHighlight = false;
|
|
13818
14070
|
actionBtn.classList.remove("vditor-menu--current");
|
|
@@ -13856,8 +14108,12 @@ var process_processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
|
13856
14108
|
useHighlight = false;
|
|
13857
14109
|
actionBtn.classList.add("vditor-menu--current");
|
|
13858
14110
|
}
|
|
13859
|
-
else if (commandName === "italic" ||
|
|
13860
|
-
|
|
14111
|
+
else if (commandName === "italic" ||
|
|
14112
|
+
commandName === "bold" ||
|
|
14113
|
+
commandName === "strike" ||
|
|
14114
|
+
commandName === "inline-code" ||
|
|
14115
|
+
commandName === "code" ||
|
|
14116
|
+
commandName === "table") {
|
|
13861
14117
|
var html = void 0;
|
|
13862
14118
|
if (range.toString() === "") {
|
|
13863
14119
|
html = "".concat(prefix, "<wbr>").concat(suffix);
|
|
@@ -13886,10 +14142,16 @@ var process_processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
|
13886
14142
|
(0,selection/* setSelectionFocus */.Hc)(range);
|
|
13887
14143
|
}
|
|
13888
14144
|
}
|
|
13889
|
-
else if (commandName === "check" ||
|
|
14145
|
+
else if (commandName === "check" ||
|
|
14146
|
+
commandName === "list" ||
|
|
14147
|
+
commandName === "ordered-list") {
|
|
13890
14148
|
listToggle(vditor, range, commandName, false);
|
|
13891
14149
|
useHighlight = false;
|
|
13892
|
-
removeCurrentToolbar(vditor.toolbar.elements, [
|
|
14150
|
+
removeCurrentToolbar(vditor.toolbar.elements, [
|
|
14151
|
+
"check",
|
|
14152
|
+
"list",
|
|
14153
|
+
"ordered-list",
|
|
14154
|
+
]);
|
|
13893
14155
|
actionBtn.classList.add("vditor-menu--current");
|
|
13894
14156
|
}
|
|
13895
14157
|
}
|